
import PlayerItemXEnh, { CEnhRs } from "../../entity/PlayerItemXEnh";
import L_String from "../../utils/L_String";

export type EnhIndexItemXRel={
    enhId:number,  //强化id
    playerId:number,   
    playerEnhIndex:number,    //玩家强化索引
    itemTypeId:string //使用指定强化物品id
}

/** 玩家强化物品itemx管理容器 */
export default class PlayerEnhManager{
 
    private static G_PLAYER_IX_MAP:Map<number,PlayerItemXEnh>=new Map();

    /**<enhId,enhIndexItemXRel>  强化物品id-创建强化物品的关联信息*/
    private static G_ITEMX_ENH_REL_MAP:Map<number,EnhIndexItemXRel>=new Map();

    private static PLAYER_MAX_ENH_ITEM_NUMBER=3; //玩家拥有的最大强化物品数量

    private static G_ENHID=0; //全局自增强化id

    public static showStat(){
        console.log("-------------------")
        console.log(L_String.getObjJSONStr(this.G_PLAYER_IX_MAP))
        console.log(L_String.getObjJSONStr(this.G_ITEMX_ENH_REL_MAP))
    }

    /**
     * 获取玩家可用强化装备序列对象
     * @param playerId  玩家id 1-N
     * @returns 
     */
    public static getPlayerEnhItemTypeId(playerId:number):EnhIndexItemXRel | null{
        let playerEnhIxObj:PlayerItemXEnh | undefined=PlayerEnhManager.G_PLAYER_IX_MAP.get(playerId)
        if(playerEnhIxObj==undefined){
            playerEnhIxObj=new PlayerItemXEnh(playerId,PlayerEnhManager.PLAYER_MAX_ENH_ITEM_NUMBER,"E"+playerId);
            PlayerEnhManager.G_PLAYER_IX_MAP.set(playerId,playerEnhIxObj);
        }
        let enhItemTypeIdObj:CEnhRs|null= playerEnhIxObj.getCurEnhItemTypeId();
        if(enhItemTypeIdObj==null){
            console.log("------>无法创建新的ENH强化物品索引信息!")
            return null
        }
        PlayerEnhManager.G_ENHID+=1;
        let rs:EnhIndexItemXRel= {enhId:PlayerEnhManager.G_ENHID,
                playerId,
                playerEnhIndex:enhItemTypeIdObj.playerEnhIndex,
                itemTypeId:enhItemTypeIdObj.itemTypeIdStr
                }
        if(rs!=null) PlayerEnhManager.G_ITEMX_ENH_REL_MAP.set(PlayerEnhManager.G_ENHID,rs);
        console.log("--创建新的ENH强化物品索引信息",L_String.getObjJSONStr(rs))
        return rs;       
    }

    /**
     * 根据全局强化唯一id移除之前绑定的对象管理
     * @param enhId 强化id
     */
    public static destoryEnhItemRel(enhId:number | null){
        if(enhId==null || enhId==undefined) return
        let record:EnhIndexItemXRel | undefined=PlayerEnhManager.G_ITEMX_ENH_REL_MAP.get(enhId);
        if(record!=undefined){
            let playerEnhIxObj:PlayerItemXEnh | undefined=PlayerEnhManager.G_PLAYER_IX_MAP.get(record.playerId)
            if(playerEnhIxObj!=undefined){
                playerEnhIxObj.destroyEnhItemx(record.playerEnhIndex)
                PlayerEnhManager.G_ITEMX_ENH_REL_MAP.delete(enhId)
               // console.log("--摧毁ENH强化物品索引信息",L_String.getObjJSONStr(record))
            }
        }

    }

 
 

  
}  